package com.da.javatest.thread.juc.locksupport;

import java.util.concurrent.TimeUnit;

/**
 * @author chenlida
 * @date 2020/7/11 16:09
 *
 * 1.wait()/notify()/notifyAll()方法都必须放在同步代码（必须在synchronized内部执行）中执行，需要先获取锁
 *
 * 2.线程唤醒的方法（notify、notifyAll）需要在等待的方法（wait）之后执行，等待中的线程才可能会被唤醒，否则无法唤醒
 */
public class LockSupport1 {
    private static Object lock = new Object();

    public static void main(String[] args) throws InterruptedException {
        new Thread(() -> {
            synchronized (lock) {
                System.out.println(Thread.currentThread() + " start");
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread() + " end");
            }
        }).start();

        TimeUnit.SECONDS.sleep(3);
        //synchronized (myLock) {
        lock.notifyAll();
        //}
    }
}
